home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_108 / bash-108.zoo / bash-1.08 / shell.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-20  |  7.7 KB  |  232 lines

  1. /* shell.h -- The data structures used by the shell */
  2.  
  3. #include "config.h"
  4. #include "general.h"
  5. #include "variables.h"
  6. #include "quit.h"
  7.  
  8. #if defined (USG) && !defined (MAXPATHLEN)
  9. #define MAXPATHLEN 1024
  10. #endif
  11.  
  12. extern int EOF_Reached;
  13.  
  14. #define NO_PIPE -1
  15. #define REDIRECT_BOTH -2
  16. #define IS_DESCRIPTOR -1
  17.  
  18. #define NO_VARIABLE -1
  19.  
  20. /* A bunch of stuff for flow of control using setjmp () and longjmp (). */
  21.  
  22. #include <setjmp.h>
  23. extern jmp_buf top_level, catch;
  24.  
  25. #define NOT_JUMPED 0        /* Not returning from a longjmp. */
  26. #define FORCE_EOF 1        /* We want to stop parsing. */
  27. #define DISCARD 2        /* Discard current command. */
  28. #define EXITPROG 3        /* Unconditionally exit the program now. */
  29.  
  30. /* Values that can be returned by execute_command (). */
  31. #define EXECUTION_FAILURE 1
  32. #define EXECUTION_SUCCESS 0
  33.  
  34. /* Special exit status used when the shell is asked to execute a
  35.    binary file as a shell script. */
  36. #define EX_BINARY_FILE 127
  37.  
  38. /* The list of characters that are quoted in double-quotes with a
  39.    backslash.  Other characters following a backslash cause nothing
  40.    special to happen. */
  41. #define slashify_in_quotes "\\`$\""
  42. #define slashify_in_here_document "\\`$"
  43.  
  44. /* Constants which specify how to handle backslashes and quoting in
  45.    expand_word_internal ().  Q_DOUBLE_QUOTES means to use the function
  46.    slashify_in_quotes () to decide whether the backslash should be
  47.    retained.  Q_HERE_DOCUMENT means slashify_in_here_document () to
  48.    decide whether to retain the backslash.  Q_KEEP_BACKSLASH means
  49.    to unconditionally retain the backslash. */
  50. #define Q_DOUBLE_QUOTES  1
  51. #define Q_HERE_DOCUMENT  2
  52. #define Q_KEEP_BACKSLASH 3
  53.  
  54. /* All structs which contain a `next' field should have that field
  55.    as the first field in the struct.  This means that functions
  56.    can be written to handle the general case for linked lists. */
  57. typedef struct g_list {
  58.   struct g_list *next;
  59. } GENERIC_LIST;
  60.  
  61. /* Instructions describing what kind of thing to do for a redirection. */
  62. enum r_instruction { r_output_direction, r_input_direction, r_inputa_direction,
  63.              r_appending_to, r_reading_until, r_duplicating,
  64.              r_deblank_reading_until, r_close_this, r_err_and_out,
  65.              r_input_output, r_output_force };
  66.  
  67. /* Command Types: */
  68. enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple,
  69.             cm_connection, cm_function_def, cm_until, cm_group };
  70.  
  71. /* A structure which represents a word. */
  72. typedef struct word_desc {
  73.   char *word;            /* Zero terminated string. */
  74.   int dollar_present;        /* Non-zero means dollar sign present. */
  75.   int quoted;            /* Non-zero means single, double, or back quote
  76.                    or backslash is present. */
  77.   int assignment;        /* Non-zero means that this word contains an assignment. */
  78. } WORD_DESC;
  79.  
  80. /* A linked list of words. */
  81. typedef struct word_list {
  82.   struct word_list *next;
  83.   WORD_DESC *word;
  84. } WORD_LIST;
  85.  
  86.  
  87. /* **************************************************************** */
  88. /*                                    */
  89. /*            Shell Command Structs                */
  90. /*                                    */
  91. /* **************************************************************** */
  92.  
  93. /* What a redirection descriptor looks like.  If FLAGS is IS_DESCRIPTOR,
  94.    then we use REDIRECTEE.DEST, else we use the file specified. */
  95. typedef struct redirect {
  96.   struct redirect *next;    /* Next element, or NULL. */
  97.   int redirector;        /* Descriptor to be redirected. */
  98.   int flags;            /* Flag value for `open'. */
  99.   enum r_instruction  instruction; /* What to do with the information. */
  100.   union {
  101.     int dest;            /* Place to redirect REDIRECTOR to, or ... */
  102.     WORD_DESC *filename;    /* filename to redirect to. */
  103.   } redirectee;
  104.   char *here_doc_eof;        /* The word that appeared in <<foo. */
  105. } REDIRECT;
  106.  
  107. /* An element used in parsing.  A single word or a single redirection.
  108.    This is an ephemeral construct. */
  109. typedef struct element {
  110.   WORD_DESC *word;
  111.   REDIRECT *redirect;
  112. } ELEMENT;
  113.  
  114. /* Possible values for command->subshell. */
  115. #define WANT_SUBSHELL    1    /* user wants a subshell: ( command ) */
  116. #define FORCE_SUBSHELL    2    /* shell needs to force a subshell */
  117.  
  118. /* What a command looks like. */
  119. typedef struct command {
  120.   enum command_type type;    /* FOR CASE WHILE IF CONNECTION or SIMPLE. */
  121.   int subshell;            /* Non-zero means execute in a subshell. */
  122.   int invert_pipeline;        /* Non-zero means invert return value. */
  123.   REDIRECT *redirects;        /* Special redirects for FOR CASE, etc. */
  124.   union {
  125.     struct for_com *For;
  126.     struct case_com *Case;
  127.     struct while_com *While;
  128.     struct if_com *If;
  129.     struct connection *Connection;
  130.     struct simple_com *Simple;
  131.     struct function_def *Function_def;
  132.     struct group_com *Group;
  133.   } value;
  134. } COMMAND;
  135.  
  136. /* Structure used to represent the CONNECTION type. */
  137. typedef struct connection {
  138.   COMMAND *first;        /* Pointer to the first command. */
  139.   COMMAND *second;        /* Pointer to the second command. */
  140.   int connector;        /* What separates this command from others. */
  141. } CONNECTION;
  142.  
  143. /* Structures used to represent the CASE command. */
  144.  
  145. /* Pattern/action structure for CASE_COM. */
  146. typedef struct pattern_list {
  147.   struct pattern_list *next;    /* Clause to try in case this one failed. */
  148.   WORD_LIST *patterns;        /* Linked list of patterns to test, one after each other. */
  149.   COMMAND *action;        /* Thing to execute if one of the patterns match. */
  150. } PATTERN_LIST;
  151.  
  152. /* The CASE command. */
  153. typedef struct case_com {
  154.   WORD_DESC *word;        /* the thing to test. */
  155.   PATTERN_LIST *clauses;    /* the clauses to test against, or NULL. */
  156. } CASE_COM;
  157.  
  158. /* FOR command. */
  159. typedef struct for_com {
  160.   WORD_DESC *name;    /* The variable name to get mapped over. */
  161.   WORD_LIST *map_list;    /* The things to map over.  This is never NULL. */
  162.   COMMAND *action;    /* The action to execute.
  163.                During execution, NAME is bound to successive
  164.                members of MAP_LIST. */
  165. } FOR_COM;
  166.  
  167. /* IF command. */
  168. typedef struct if_com {
  169.   COMMAND *test;        /* Thing to test. */
  170.   COMMAND *true_case;        /* What to do if the test returned non-zero. */
  171.   COMMAND *false_case;        /* What to do if the test returned zero. */
  172. } IF_COM;
  173.  
  174. /* WHILE command. */
  175. typedef struct while_com {
  176.   COMMAND *test;        /* Thing to test. */
  177.   COMMAND *action;        /* Thing to do while test is non-zero. */
  178. } WHILE_COM;
  179.  
  180. /* The "simple" command.  Just a collection of words and redirects. */
  181. typedef struct simple_com {
  182.   WORD_LIST *words;        /* The program name, the arguments,
  183.                    variable assignments, etc. */
  184.   REDIRECT *redirects;        /* Redirections to perform. */
  185. } SIMPLE_COM;
  186.  
  187. /* The "function_def" command.  This isn't really a command, but it is
  188.    represented as such for now.  If the function def appears within 
  189.    `(' `)' the parser tries to set the SUBSHELL bit of the command.  That
  190.    means that FUNCTION_DEF has to be run through the executor.  Maybe this
  191.    command should be defined in a subshell.  Who knows or cares. */
  192. typedef struct function_def {
  193.   WORD_DESC *name;
  194.   COMMAND *command;
  195. } FUNCTION_DEF;
  196.  
  197. /* A command that is `grouped' allows pipes to take effect over
  198.    the entire command structure. */
  199. typedef struct group_com {
  200.   COMMAND *command;
  201. } GROUP_COM;
  202.   
  203. /* Forward declarations of functions called by the grammer. */
  204. extern REDIRECT *make_redirection ();
  205. extern WORD_LIST *make_word_list ();
  206. extern WORD_DESC *make_word ();
  207.  
  208. extern COMMAND
  209.   *make_for_command (), *make_case_command (), *make_if_command (),
  210.   *make_while_command (), *command_connect (), *make_simple_command (),
  211.   *make_function_def (), *clean_simple_command (), *make_until_command (),
  212.   *make_group_command ();
  213.  
  214.  
  215. extern PATTERN_LIST *make_pattern_list ();
  216. extern COMMAND *global_command, *copy_command ();
  217.  
  218. extern char **shell_environment;
  219. extern WORD_LIST *rest_of_args;
  220.  
  221. /* Generalized global variables. */
  222. extern int executing, login_shell;
  223.  
  224. /* Structure to pass around that holds a bitmap of file descriptors
  225.    to close, and the size of that structure.  Used in execute_cmd.c. */
  226. struct fd_bitmap {
  227.   long size;
  228.   char *bitmap;
  229. };
  230.  
  231. #define FD_BITMAP_SIZE 32
  232.